package thread;

/**
 * @author: omybug
 * @date: 18/11/19 10:50
 */
public class YiledTest extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
//            try {
//                Thread.sleep(1L);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            if (i >= 2 && "A".equals(this.getName())) {
                Thread.yield();
            }
            System.out.println( this.getName() + " - 第" + i + "次执行！");
        }
    }

    public YiledTest(String name) {
        super(name);

    }

    public YiledTest(){
        Thread t1 = new Thread(new YiledTest("A"));
        Thread t2 = new Thread(new YiledTest("B"));
        t1.start();
        t2.start();
    }

    public static void main(String[] args) {
        YiledTest ts = new YiledTest();
    }
}
